﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore.Data.Items;
using Workflow.Alerts.DAL;
using Workflow.Alerts.Interfaces.ProfileSettings;

namespace Workflow.Alerts
{
    public class StartFeePresenter : Presenter
    {
        #region members        
        private readonly IStartFeeView view;
        private readonly UserDAL model;
        #endregion

        #region constructor
        public StartFeePresenter(IStartFeeView _view)
            : this(_view, null)
        { }

        public StartFeePresenter(IStartFeeView _view, ISessionProvider session)
            : base(_view, session)
        {
            view = base.GetView<IStartFeeView>();

            view.OnPageLoad += view_Load;
            view.OnUpdate += view_Update;
            model = new UserDAL();
        }

        #endregion

        #region private methods

        private void view_Update()
        {
            var filter = new WorkflowFilter
            {
                MunicipalityId = CurrentUser.MunicipalityId,
                StartFee=view.Fee
            };
           
            var filterSql = new WorkflowFilterSql(filter);
            model.UpdateStartFee(filterSql);
        }

        private void view_Load()
        {
            var filter = new WorkflowFilter
            {
                MunicipalityId = CurrentUser.MunicipalityId
            };

            var filterSql = new WorkflowFilterSql(filter);
            view.Fee = model.GetStartFee(filterSql);
        }

        #endregion
    }
}
